Skip to main content
Glama
save.ts1.47 kB
import { resolveFromUserData } from "@/helpers/paths"; import { extractMcpName } from "@/http/server/utils"; export const saveConfiguration = async (pathname: string, req: Request) => { const mcpNameResult = extractMcpName(pathname, "config"); // Handle potential Response error from mcpName extraction if (mcpNameResult instanceof Response) { return mcpNameResult; } try { // If we got here, mcpNameResult is a string const mcpName = mcpNameResult; const configurationPath = await resolveFromUserData("configuration.json"); let configuration = await Bun.file(configurationPath).json(); // Get the specific MCP configuration const mcpConfig = configuration.installed[mcpName]; // Replace the configuration with the new one // (eg. only replace the inputs of the configuration, don't replace any config that does not presently exist) const newConfig = await req.json(); Object.keys(newConfig).forEach((key) => { if (mcpConfig[key]) { mcpConfig[key] = newConfig[key]; } }); // Save the configuration configuration.installed[mcpName] = mcpConfig; await Bun.write(configurationPath, JSON.stringify(configuration, null, 2)); return new Response(JSON.stringify({ success: true, data: mcpConfig })); } catch (error) { return new Response( JSON.stringify({ success: false, error: `Failed to save configuration: ${error}`, }) ); } };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ashwwwin/furi'

If you have feedback or need assistance with the MCP directory API, please join our Discord server